local skel = fk.CreateSkill {
  name = "lb__duanjie",
  max_branches_use_time = {
    ["damage"] = {
      [Player.HistoryRound] = 1
    },
  }
}

Fk:loadTranslationTable {
  ["lb__duanjie"] = "断界",
  [":lb__duanjie"] = "每轮限一次，当你对一名本回合失去过牌的角色造成伤害后，你可以选择一项：<br>" ..
      "1.其翻面且你下个摸牌阶段少摸一张牌；<br>" ..
      "2.视为使用一张【杀】。",

  ["@lb__duanjie"] = "断界",
  ["#lb__duanjie-skip"] = "少摸牌",
  ["#lb__duanjie"] = "断界：你可以视为使用一张【杀】或令 %dest 翻面且你下个摸牌阶段少摸一张牌",
  ["#lb__duanjie-ask"] = "断界：你可以视为使用一张【杀】，或取消后令 %dest 翻面且你下个摸牌阶段少摸一张牌",

  ["$lb__duanjie1"] = "见识一下星辰粉碎的样子吧！",
  ["$lb__duanjie2"] = "现在离开还来得及。",
}

skel:addEffect(fk.Damage, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(skel.name) and target == player and player:usedSkillTimes(skel.name, Player.HistoryRound, "damage") == 0 then
      return #player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
        for _, move in ipairs(e.data) do
          if move.from and move.from == data.to then
            for _, info in ipairs(move.moveInfo) do
              if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                return true
              end
            end
          end
        end
      end, Player.HistoryTurn) > 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = skel.name,
      prompt = "#lb__duanjie::" .. data.to.id,
    })
  end,
  on_use = function(self, event, target, player, data)
    player:addSkillBranchUseHistory(skel.name, "damage")
    local room = player.room
    local use = room:askToUseVirtualCard(player, {
      name = "slash",
      skill_name = skel.name,
      prompt = "#lb__duanjie-ask::" .. data.to.id,
    })
    if use == nil then
      data.to:turnOver()
      room:setPlayerMark(player, "@lb__duanjie", "#lb__duanjie-skip")
    end
  end,
}, { check_skill_limit = true})
--[[
skel:addEffect(fk.EventPhaseChanging, {
  anim_type = "negative",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and data.phase == Player.Draw and
    player:getMark("@lb__duanjie") ~= 0
  end,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@lb__duanjie", 0)
    data.skipped = true
  end,
})
--]]
skel:addEffect(fk.DrawNCards, {
  anim_type = "negative",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and data.n > 0 and player:getMark("@lb__duanjie") ~= 0
  end,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@lb__duanjie", 0)
    data.n = data.n - 1
  end,
})

skel:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, "@lb__duanjie", 0)
end)

return skel